package space.enemy;

import java.util.ArrayList;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;

public class BrickManager {
	
	ArrayList<Brick> mattoni = new ArrayList<Brick>();
	Engine engine;
	
	private TextureRegion mMattoneTextureRegion;
	private TextureRegion mMattoneTextureRegion2;
	private TextureRegion mMattoneTextureRegion3;
	private TextureRegion mMattoneTextureRegion4;

	private SpaceEnemyController sec;
	
	private int startX;
	private int startY;
	private Scene scene;
	
	public BrickManager(Scene scene, Texture texture,SpaceEnemyController sec){
		this.sec=sec;
		this.scene = scene;
		this.mMattoneTextureRegion = TextureRegionFactory.createFromAsset(texture, sec, "gfx/mattone1.png", 0, 0);
		
		this.mMattoneTextureRegion2 = TextureRegionFactory.createFromAsset(texture, sec, "gfx/mattone1.png", 16, 32);
		this.mMattoneTextureRegion3 = TextureRegionFactory.createFromAsset(texture, sec, "gfx/mattone1.png", 32, 16);
		this.mMattoneTextureRegion4 = TextureRegionFactory.createFromAsset(texture, sec, "gfx/mattone1.png", 32, 32);		
	
	}
	
	public void createBrick(){
		Brick mattone = new Brick(startX,startY,mMattoneTextureRegion,40,scene);
		mattoni.add(mattone);	   
	   	
	   	Brick mattone3 = new Brick(startX,startY+15,this.mMattoneTextureRegion3,40,scene);
		mattoni.add(mattone3);
	   	
		Brick mattone4 = new Brick(startX+15,startY,this.mMattoneTextureRegion4,40,scene);
	  	mattoni.add(mattone4);
	   	
	   	Brick mattone2 = new Brick(startX+15,startY+15,this.mMattoneTextureRegion2,40,scene);
	 	mattoni.add(mattone2);
	}
	public ArrayList<Brick> getMattoni() {
		return mattoni;
	}

	public void removeMattone(final Sprite mattone) {
		engine.runOnUpdateThread(new Runnable() {
			@Override
			public void run() {
				//cancello
				engine.getScene().getLastChild().detachChild(mattone);
				mattoni.remove(mattone);	        				
			}
		});
	}
	public Engine getEngine() {
		return engine;
	}

	public void setEngine(Engine engine) {
		this.engine = engine;
	}

	public void setStartX(int i) {
		this.startX = i;
	}

	public void setStartY(int i) {
		this.startY = i;		
	}

}
